package com.njzxw.fs.commonutil.db;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * 开启sql配置 druil
 */
@EnableTransactionManagement
@Configuration
@RefreshScope
public class DbConfig {

    @Value("druil.allow")
    private String allow;

    @Value("druil.deny")
    private String deny;

    @Value("druil.loginUsername")
    private String loginUsername;

    @Value("druil.loginPassword")
    private String loginPassword;

    @Value("druil.resetEnable")
    private String resetEnable;

    @Bean
    public DataSource dataSource(Environment environment) {
        return DruidDataSourceBuilder
                .create()
                .build(environment, "spring.datasource.druid.");
    }

}
